package com.lucker.service;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;

public class RedisTest2 {

	
	
	 public static void main(String[] args) throws Exception {
	        //连接redis
	        Jedis redis = new Jedis("r-uf6cfc3e640dd254pd.redis.rds.aliyuncs.com", 6379, 400000);
	        redis.auth("Wangjianhua123");

//	        redis.select(0);
//	        redis.flushDB();
//	        //hmset
//	        long start = System.currentTimeMillis();
//	        //直接hmset
//	        for (int i = 0; i < 10000; i++) {
//	            redis.sadd("test:ss:" + i , "val" + i);
//	        }
//	        long end = System.currentTimeMillis();
//	        System.out.println("dbsize:[" + redis.dbSize() + "] .. ");
//	        System.out.println("hmset without pipeline used [" + (end - start) / 1000 + "] seconds ..");
	        
	        
	        
	        
	        redis.select(0);
	        redis.flushDB();
	        
	        
	        
	        //使用pipeline hmset
	        Pipeline p = redis.pipelined();
	        long start = System.currentTimeMillis();
	        for (int i = 0; i < 10000; i++) {
	            
	            p.sadd("test:ss:" + i , "val" + i);
	        }
	        p.sync();
	        long end = System.currentTimeMillis();
	        System.out.println("dbsize:[" + redis.dbSize() + "] .. ");
	        System.out.println("hmset with pipeline used [" + (end - start) / 1000 + "] seconds ..");
	        
	        redis.disconnect();
	    }
}
